﻿using System;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Geoprocessor;
using ESRI.ArcGIS.Geoprocessing;
using DEMM.Dependency;
using ESRI.ArcGIS.Analyst3DTools;

namespace DEMM {

    class GeoDataTransfer {

        public bool TINtoDEM(ArgsData args)
        {
            bool flag = false;
            Geoprocessor gp = new Geoprocessor
            {
                OverwriteOutput = true
            };

            args.SetPathOutputExt("tif");

            TinRaster tinRaster = new TinRaster();
            tinRaster.in_tin = args.GetPathInput(); // 输入TIN路径
            tinRaster.out_raster = args.GetPathOutput(); // 输出栅格路径
            tinRaster.data_type = args.GetOutType(); // 输出数据类型：FLOAT或INT
            tinRaster.method = args.GetTransMethod(); // 插值方法：LINEAR或NATURAL_NEIGHBORS
            tinRaster.sample_distance = "CELLSIZE " + args.GetCellSizeStr(); // 采样距离/像元大小
            tinRaster.z_factor = 1.0; // Z值因子

            try
            {
                // 执行工具
                IGeoProcessorResult result = gp.Execute(tinRaster, null) as IGeoProcessorResult;
                flag = (result.Status == esriJobStatus.esriJobSucceeded);
            }
            catch(Exception e)
            {
                Console.Write(e.ToString());
            }
            finally
            {
                // 输出消息
                Console.WriteLine("\n地理处理消息：");
                for (int i = 0; i < gp.MessageCount; i++)
                {
                    Console.WriteLine(gp.GetMessage(i));
                }
            }

            return flag;
        }
    }
}
